﻿@using Microsoft.AspNetCore.Components.Web

<AvoidLambdaExpressionInLoopsInBlazor_RenderFragment>
    @foreach (var button in Buttons)
    {
        <button @key="button.Id" @onclick="(e) => button.Action(e)"> @* Noncompliant *@
            Button #@button.Id
        </button>
    }
    
    @foreach (var button in Buttons.Where(x => x.Id == "SomeId")) @* Compliant *@
    {
        <button @key="button.Id" @onclick="(e) => button.Action(e)"> @* Noncompliant *@
            Button #@button.Id
        </button>
    }
</AvoidLambdaExpressionInLoopsInBlazor_RenderFragment>

@code {
    private List<Button> Buttons { get; } = new List<Button>();

    private void DoAction(MouseEventArgs e, Button button) { }

    private class Button
    {
        public string Id { get; } = Guid.NewGuid().ToString();
        public Action<MouseEventArgs> Action { get; set; } = e => { };
    }

    private void Reset(MouseEventArgs mouseEventArgs)
    {
        Console.WriteLine($"Reset from {mouseEventArgs}");
    }
}